package fr.mma.livraison.channel;

import javax.servlet.http.HttpServlet;

import com.google.appengine.api.channel.ChannelMessage;
import com.google.appengine.api.channel.ChannelService;
import com.google.appengine.api.channel.ChannelServiceFactory;
import com.google.gson.Gson;

import fr.mma.livraison.channel.dto.Message;
import fr.mma.livraison.channel.persistance.Channel;

public class MessageEnabledServlet extends HttpServlet {
	
	/**	 */
	private static final long serialVersionUID = 5258144514558719434L;

	protected void sendMessage(Channel channel, Message message) {
		final Gson gson = new Gson();
		for (String channelKey : channel.getChannelKeyList()) {
			ChannelService channelService = ChannelServiceFactory.getChannelService();
			channelService.sendMessage(new ChannelMessage(channelKey, gson.toJson(message)));
		}
	}
}
